package com.opencee.common.model;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.opencee.common.constants.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

/**
 * @author admin
 */
@Data
@ApiModel(value = "错误响应结果")
@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
public class ApiErrorResult<T> extends ApiResult {
    private static final long serialVersionUID = -6190689122701100762L;
    /**
     * 错误类型
     */
    @ApiModelProperty(value = "错误消息")
    private String error;

    /**
     * 请求路径
     */
    @ApiModelProperty(value = "请求路径")
    private String path;

    public ApiErrorResult errorMsg(String message) {
        this.error = message;
        return this;
    }

    /**
     * 默认返回消息内容
     *
     * @return
     */
    public static ApiErrorResult error(String error) {
        return error(ResultCode.INTERNAL_SERVER_ERROR, error);
    }

    public static ApiErrorResult error(ResultCode code, String error) {
        ApiErrorResult body = new ApiErrorResult();
        body.errorMsg(error)
                .code(code.getCode())
                .msgI18n(code.getMessageCode());
        return body;
    }

    public static ApiErrorResult error(int code, String message, String error) {
        ApiErrorResult body = new ApiErrorResult();
        body.errorMsg(error)
                .code(code)
                .msg(message);
        return body;
    }
}
